/*卡联盟用户评论列表*/
//获取联盟卡类型
var cardType = globalFun.GetQueryString("id") //联盟卡类型h
var level = globalFun.GetQueryString("type") //评价类型 0-全部/1-好评/2-中评/3-差评
//获取用户信息
var klm = {
	level: level, //评价类型
	page: 1, //页码
	rows: 10, //每页显示数据数量
	cardtype: 0 //卡联盟类型
}
//从联盟卡详情页跳转详情列表对应评价类型
if(level == 0) { //全部
	$('.quanbu').css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');
} else if(level == 1) { //好评
	$('.haoping').css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');
} else if(level == 2) { //中评
	$('.zhongping').css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');
} else if(level == 3) { //差评
	$('.chaping').css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');
}
//获取页面数据
function getdata() {
	$.ajax({
		type: "post",
		url: apicom + "mobile/view/clubcard/getClubCardCommentList",
		//	 	url:"http://192.168.50.248:10001/mobile/after/clubcard/getClubCardCommentList",
		data: klm,
		dataType: "json",
		success: function(res) {
			if(typeof(res) == 'string') {
				res = JSON.parse(res);
			}
			if(res.code == 1) {
				var data = res.content;
				console.log(data);
				console.log(data.sumStart);
				$('.pinglunshu1').text(data.sumStart); //全部评价数量
				$('.pinglunshu2').text(data.goodStart); //好评数量
				$('.pinglunshu3').text(data.middleStart); //中评数量
				$('.pinglunshu4').text(data.lakStart); //差评数量	
				var content = "";
				var datalist = data.orderCommentList
				for(var l = 0; l < datalist.length; l++) {
					var data = datalist[l]
					content += '<div><div class="current-in"><ul><li class="current-tx">'
					content += '<img src = "' + data.logAddress + '" />'
					content += '</li> <li class = "current-name" ><div>' + data.nickname + '</div>';
					content += '<div class="current-xj">'
					for(var i = 0; i < 5; i++) {
						if(i < data.startNum) {
							content += '<img src = "../../img/d_staryou.png" />'
						} else {
							content += '<img src = "../../img/d_starwu.png" />'
						}
					}
					content += '</div></li>'
					content += '<li class = "current-time" >';
					content += '<span class="current-time1">' + data.createdTime + '</span></li></ul>';

					content += '<div class = "current-hp" >';
					content += '<span class="current-hp1">' + data.content + '</span> </div >';

					if(data.picture) {
						content += '<div class = "current-tp" >'
						var picture = data.picture.split(",")
						for(var i = 0; i < picture.length; i++) {
							content += '<div style="background-image:url(' + picture[i] + ')"></div>'
						}
						content += '</div>'
					}
					content += '<div class = "active1"><span class="liulan">浏览<b>' + data.clubNum + '次</b></span><span data-id="' + data.id + '" class = "dianzan">'
					if(data.isFabuNum == 0) {
						content += '<img data-type="1" src="../../img/a_zan.png"/>'
					} else {
						content += '<img data-type="2" src="../../img/a_zan_1.png"/>'
					}
					content += '<b>' + data.fabuNum + '</b> </span >'
					content += '<span class = "pinglun" data-name="'+data.nickname+'" data-mm="'+data.memberId+'" data-id="' + data.id + '">'
					content += '<img src="../../img/w_huifu.png"/><b>评论</b></span></div>'
					if(data.childList.length!=0){
						content+='<div id="hf_hf">'
						for(var i = 0; i < data.childList.length; i++){
							content+='<div class="home_sjhf"><img src="../../img/w_huifu.png" class="sjhf" /><span>'+data.childList[i].childNickname +'"："'+data.childList[i].content +'</span></div>'
						}
						content+='</div>'
					}
					content+='</div>'
				}
				$(".conent1").html(content)

			} else {
				tips(res.msg);
			}
		},
		error: function(err) {
			console.log(err)
		}
	})
}
getdata()
//全部
$('.quanbu').click(function() {
	klm.level = 0;
	getdata()
	$(this).css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');

});
//好评
$('.haoping').click(function() {
	klm.level = 1;
	getdata()
	$(this).css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');
});
//中评
$('.zhongping').click(function() {
	klm.level = 2;
	getdata()
	$(this).css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');
});
//差评
$('.chaping').click(function() {
	klm.level = 3;
	getdata()
	$(this).css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');
});
//评论点赞--------------------------------------------------------------------------------------------------------------------------
$(document).on('click', '.dianzan', function() {
		if(Auth()) {
			uuid = user_info.uuid;
			phone = user_info.phone;
			id  = user_info.id;
		}else{
			toClientLogin()
		}
	var kid = $(this).attr('data-id');
	var zt = $(this).children("img").attr("data-type");
	var znum = $(this).children("b").html();
	console.log(znum);
	if(!Auth()) {
		toClientLogin();
	} else {
		if(zt == 1) {
			$.ajax({
				type: "post",
				url: apicom + "mobile/after/consulationfabulous/fabulous",
				//	 			url:"http://192.168.50.248:10001/mobile/after/clubcard/getClubCardCommentList",
				data: {
					consultationId: '',
					type: 1,
					planId: '',
					consultationType: 5,
					consultationCommentId: '',
					orderCommentId: kid,
					phone: phone,
					uuid: uuid
				},
				success: function(res) {
					if(typeof res == "string") {
						var data = JSON.parse(res);
					} else {
						var data = res;
					}
					if(data.code == 1) {
						tips(data.msg);
						getdata()
					} else {
						tips(data.msg)
					}
				},
				error: function(err) {
					tips("服务器错误!");
				}
			});
		} else {
			$.ajax({
				type: "post",
				url: apicom + "mobile/after/consulationfabulous/fabulous",
				data: {
					consultationId: '',
					type: 2,
					planId: '',
					consultationType: 5,
					consultationCommentId: '',
					orderCommentId: kid,
					phone: phone,
					uuid: uuid
				},
				success: function(res) {
					if(typeof res == "string") {
						var data = JSON.parse(res);
					} else {
						var data = res;
					}
					if(data.code == 1) {
						tips(data.msg);
						getdata()
					} else {
						tips(data.msg)
					}
				},
				error: function(err) {
					tips("服务器错误!");
				}
			});
		}
	}

});
// 回复评论-------------------------------------------------------------------------------------------------------------------------
$('.center_box').on('click',function(){
	$('.projectileFrame').hide();
})
//点击回复 弹框出现
var img = sessionStorage.getItem('da');
$('.shangp').attr('src', img);
var plid;//被评论的id
var nicheng;//被评论的昵称
var mid;//被评论的memberid
$(document).on('click', '.pinglun', function() {
	if(Auth()){
		$('.projectileFrame').show();
		plid = $(this).attr('data-id');
		mid = $(this).attr('data-mm');
		nicheng = $(this).attr('data-name');
		console.log(plid)
	}else{
		toClientLogin()
	}
	
	
})
//点击回复 弹框消失
$('.huifu').on('click', function() {
	var zxContent = $(".replyText").val();
	if(zxContent == "" || zxContent.length == 0) {
		tips("评论内容不能为空");
		return false;
	}else if(zxContent.length > 140) {
		tips("评论内容不能超过140字");
		return false;
	}else{
		var pl = {
			id:id,//当前用户id
			commentId:plid,//父级评论id
			content:zxContent,//评论内容
			operationId:mid,//当前评论的memberid
			objectName:nicheng,//当前评论的昵称
			operationObjectId:plid,//父级评论id
			uuid:uuid,
			phone:phone
		}
			$.ajax({
			type:"post",
			url:apicom+"mobile/after/order/ordercomment/replyComment",
			data:pl,
			async:true,
			success:function(res){
				if(res.code==1){
					tips(res.msg)
					$('.projectileFrame').hide();
					$(".replyText").val('')
					getdata()
				}else{
					tips(res.msg)
				}
			},
			error:function(err){
				console.log(err)
			}
		});
	}	
});

//分享---------------------------------------------------------------------------------------------------------------
	$('.navFx-img').on('click',function(){
		console.log(1)
    	if(Auth()){
    			uuid=user_info.uuid,
    			phone=user_info.phone,
    			memberId=user_info.id
    	} else{
    		sessionStorage.setItem('history', window.location.href);
    		toClientLogin(location.href)
    	}

    		var $self = $(this)
    		if($self.hasClass("disabled")){
    			return false
    		}
    		$self.addClass("disabled")
    		setTimeout(function(){
    			$self.removeClass("disabled")
    		},1000)
    		var shareMsg = localStorage.getItem("share_url");
    		shareMsg = JSON.parse(shareMsg)

	  var data = {
	    type: 1,
	    url:shareMsg.url,
	    title: shareMsg.title,
	    content:shareMsg.content,
	    imgUrl:shareMsg.imgUrl
	  }
	  console.log(data)
	  zhuanfa(data);
	})
	//分享
function zhuanfa(data) {
  if (mark == 1) {
    setupWebViewJavascriptBridge(function(bridge) {
      bridge.callHandler("jsToClientShare", data, function(data, responseCallback) {});
    });
  } else if (mark == 0) {
    var shareData = JSON.stringify(data);
    window.stub.jsToClientShare(shareData);
  }
};

